package cn.qinhao.pethome.login.controller;

import cn.qinhao.pethome.basic.exception.BusinessException;
import cn.qinhao.pethome.basic.until.AjaxResult;
import cn.qinhao.pethome.login.domain.RegisterVo;
import cn.qinhao.pethome.login.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    private RegisterService registerService;
    @PostMapping
    public AjaxResult userRegister(@RequestBody RegisterVo registerVo){
        try {
            registerService.userRegister(registerVo);
            return AjaxResult.me().setSuccess(true);
        } catch (BusinessException e) {
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("网络服务异常！！！");
        }
    }
}
